from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.metrics import recall_score
from sklearn.metrics import precision_score
from sklearn.metrics import f1_score

import pandas as pd
import matplotlib.pyplot as plt
import numpy as py
import numpy as np

#1.加载数据
X,y = load_breast_cancer(return_X_y=True)     #快速获得参数
print(np.shape(X),np.shape(y))
X_train,X_test,y_train,y_test = train_test_split (X,y,test_size = 0.15)

#2.指定分类模型
lr = LogisticRegression(max_iter=1000)

#3.训练模型
lr.fit(X_train,y_train)

#4.评估模型    metrics 什么问题用什么指标评估（acc准确率、precision精确率、recall召回率、f1）
sum0,sum1,sum2,sum3 = 0,0,0,0
ave0,ave1,ave2,ave3 = 0,0,0,0
for i in range(10):
    x = accuracy_score(y_test,lr.predict(X_test))
    sum0 +=x
    ave0 = sum0/10
    y = precision_score(y_test,lr.predict(X_test))
    sum1 += y
    ave1 = sum1/10
    z = recall_score(y_test,lr.predict(X_test))
    sum2 += z
    ave2 = sum2/10
    a = f1_score(y_test,lr.predict(X_test))
    sum3 += a
    ave3 = sum3/10
print(ave0)
print(ave1)
print(ave2)
print(ave3)



#5.预测模型